package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.Historyinfo;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.task.CallbackSky;
import artid.com.arttogo.utils.NetUtils;

//机构详情里所有拍卖会的adapter
public class LotIntroHisListAdapter extends BaseAdapter {
	private Context mContext;
	LayoutInflater mInflater;
	ViewHolder holder;
	CallbackSky cs;
	public ArrayList<Historyinfo> list;
	String width;
	public LotIntroHisListAdapter(Context mContext, ArrayList<Historyinfo> list) {
		this.mContext = mContext;
		mInflater = LayoutInflater.from(mContext);

		Map<String, String> map = NetUtils
				.getDisplayMetrics((Activity)mContext);
		width = String.valueOf(Integer.valueOf(map.get(NetUtils.DM_WIDTH))/2);
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public void setData(ArrayList<Historyinfo> listin) {
		list = listin;
		notifyDataSetChanged();
	}
	public void addData(List<Historyinfo> listin) {
		list.addAll(listin);
		notifyDataSetChanged();
	}
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
		if (convertView == null) {
			vh = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_lot_intro_list_auchis, null);
			vh.his_list_iv = (ImageView) convertView.findViewById(R.id.his_list_iv);
			vh.his_list_name = (TextView) convertView.findViewById(R.id.his_list_name);
			vh.his_list_cate_title = (TextView) convertView.findViewById(R.id.his_list_cate_title);
			vh.his_list_time = (TextView) convertView.findViewById(R.id.his_list_time);
			vh.his_list_price = (TextView) convertView.findViewById(R.id.his_list_price);
			vh.his_list_grow = (TextView) convertView.findViewById(R.id.his_list_grow);
			vh.trend= (ImageView)convertView.findViewById(R.id.trend);
			/* Please visit http://www.ryangmattison.com for updates */
			/* Please visit http://www.ryangmattison.com for updates */
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}
		Historyinfo item = list.get(position);
		if (!TextUtils.isEmpty(item.getJigou_logo())) {
			Glide.with(mContext).load(item.getJigou_logo()+ AppUtil.picWidthUrl)
			.placeholder(R.drawable.ic_menu_rotate)
			.error(R.drawable.ic_menu_rotate).into(vh.his_list_iv);
		}
		vh.his_list_name.setText(item.getSeller_name());
		vh.his_list_cate_title.setText(item.getAuction_title()+"/"+item.getSpecial_title());
		vh.his_list_time.setText(item.getAuction_start_time());
		vh.his_list_price.setText(item.getLot_price());
		String state = "";
		if (item.getMom_status().equals("1")) {
			state = "环比增长"+item.getMom_price();
			vh.trend.setImageResource(R.drawable.toup);
		}else  if (item.getMom_status().equals("2")) {
			state = "环比减少"+item.getMom_price();
			vh.trend.setImageResource(R.drawable.todown);
		}else {
			state = "环比持平";
			vh.trend.setImageResource(R.drawable.toflat);
		}
		vh.his_list_grow.setText(state);

		return convertView;
	}

	class ViewHolder {
		/**********DECLARES*************/
		private ImageView his_list_iv,trend;
		private TextView his_list_name;
		private TextView his_list_cate_title;
		private TextView his_list_time;
		private TextView his_list_price;
		private TextView his_list_grow;
		
		/**********INITIALIZES*************/
		
	}
}
